package com.example.last.controller;

import com.example.last.common.Result;
import com.example.last.entity.Params;
import com.example.last.entity.Propagate;
import com.example.last.entity.Test;
import com.example.last.service.TestService;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin
@RequestMapping("/test")
@RestController
public class TestController {
    @Resource
    private TestService testService;
    
    @GetMapping("/search")
    public Result findBySearch(@Param("params") Params params){
        PageInfo<Test> info = testService.findBySearch(params);
        return Result.success(info);
    }

    //新增信息
    @PostMapping
    public Result save(@RequestBody Test test){
        if(test.getId() == null){
            testService.add(test);
        }else{
            testService.update(test);
        }
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        testService.delete(id);
        return Result.success();
    }

    //批量删除
    @PutMapping("/batch")
    public Result batchdel(@RequestBody List<Test> list){
        for(Test test : list){
            testService.delete(test.getId());
        }
        return Result.success();
    }


}
